import {
    baseUrl
} from "../../static/url"
import {
    httpRequest
} from "../../utils/request"
Page({
    data: {
        titleValue : 0,
        searchValue : "",
        cityText: '所有状态',
        cityValue: [],
        cityTitle: '',
        cityVisible: false,
        stickyProps: {
            zIndex: 0,
        },
        citys: [{
                label: '所有状态',
                value: '所有状态'
            },
            {
                label: '待处理',
                value: '待处理'
            },
            {
                label: '已完成',
                value: '已完成'
            },
        ],

        list: [
        ],
        loading: false,
        page :1,
        pagesize :20,
        total :0,
        shareTitle : "检修单",
        shareCoding : "-",
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log(options)
        // this.getlist()
    },
    onShow() {
        this.getlist()
    },
    shares(e){
        console.log(e)
        this.setData({
            shareTitle : e.currentTarget.dataset.title,
            shareCoding : e.currentTarget.dataset.coding
        })
    },
    goto(e){
        let address = e.currentTarget.dataset.address
        address = address.split(',')
        wx.openLocation({
          latitude: parseFloat(address[1]),
          longitude: parseFloat(address[0]),
        })
    },
    onShareAppMessage(e) {
        console.log(e)
         setTimeout(function(){

        }, 100)
        return {
            title: this.data.shareTitle,
            path: '/pages/detail/detail?bill_coding=' + this.data.shareCoding + '&fx=22',
            imageUrl: '/static/image/banner.png'
          }

    },
    watch(e){
        let id = e.currentTarget.dataset.id
        wx.navigateTo({
          url: '/pages/detail/detail?bill_coding=' + id,
        })
    },
    list_search(e){
        console.log(e)
        this.setData({
            searchValue : e.detail.value
        })
        this.getlist()
    },
    getlist(){
        let that = this
        that.setData({
            loading : true
        })
        let requestForm = {
            page : that.data.page, 
            pagesize : that.data.pagesize, 
            cityText : that.data.cityText,
            titleValue : that.data.titleValue,
            searchValue : that.data.searchValue,
        };
        httpRequest("repair/bill/list", 'POST', requestForm).then(r =>{
            that.setData({
                list : r.data.list.data,
                total : r.data.total,
                loading : false
            })
        })

    },
    onTabsChange(event) {
        console.log(`Change tab, tab-panel value is ${event.detail.value}.`);
        this.setData({
            titleValue : event.detail.value
        })
        this.getlist()
    },

    onTabsClick(event) {
        console.log(`Click tab, tab-panel value is ${event.detail.value}.`);
    },

    onStickyScroll(event) {
        console.log(event.detail);
    },
    onColumnChange(e) {
        console.log('picker pick:', e);
    },

    onPickerChange(e) {
        const {
            key
        } = e.currentTarget.dataset;
        const {
            value
        } = e.detail;

        console.log('picker change:', e.detail);
        this.setData({
            [`${key}Visible`]: false,
            [`${key}Value`]: value,
            [`${key}Text`]: value.join(' '),
        });
        this.getlist()
    },

    onPickerCancel(e) {
        const {
            key
        } = e.currentTarget.dataset;
        console.log(e, '取消');
        console.log('picker1 cancel:');
        this.setData({
            [`${key}Visible`]: false,
        });
    },

    onTitlePicker() {
        this.setData({
            cityVisible: true,
            cityTitle: '选择类型'
        });
    },

    onWithoutTitlePicker() {
        this.setData({
            city2Visible: true,
            city2Title: ''
        });
    },
});